%% algorithm and code example
\documentclass{article}

\usepackage{dsfont}
\usepackage{mathtools}

\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}

\algnewcommand{\Local}{\State\textbf{local variables: }}
\newcommand{\minbox}[2]{%
    \mathmakebox[\ifdim#1<\width\width\else#1\fi]{#2}}
\newcommand{\Let}[2]{\State $ \minbox{1em}{#1} \gets #2 $}

% sourcecode for color
\usepackage{xcolor}
\usepackage{inconsolata}
\newcommand{\Cpp}{C\texttt{++}}

%% listing for source code
\usepackage{listings}

\lstset{
language = C++,
basicstyle = \ttfamily,
keywordstyle = \color{blue}\textbf,
commentstyle = \color{gray},
stringstyle = \color{green!70!black},
stringstyle = \color{red},
columns = fullflexible,
numbers = left,
numberstyle = \scriptsize\sffamily\color{gray},
caption = A hello world program in \Cpp,
xleftmargin = 0.16\textwidth,
xrightmargin = 0.16\textwidth,
showstringspaces = false,
float,
}





\begin{document}

\section{Algorithm}

\begin{algorithm}
    \caption{Mandelbrot set}
\label{alg:mandelbrot}
\begin{algorithmic}[1]

\Require{$c_x, c_y, \Sigma_{\max} \in \mathds{R},\quad I \in \mathds{N}, \quad i_{\max} > 0,\quad \Sigma_{\max} > 0$}
\Function{mandelbrot}{$c_x, c_y, i_{\max},\Sigma_{\max}$}

    \Local{$x, y, x^\prime, y^\prime, i, \Sigma$}

    \Let{x, y, i, \Sigma}{0}
    \Comment{initial zero value for all}

    \While{$\Sigma \leq \Sigma_{\max}$ and $i < i_{\max}$}
    \Let{x^\prime}{x^2 - y^2 + c_x}
    \Let{y^\prime}{2xy + c_y}
    \Let{m}{x^\prime}
    \Let{y}{y^\prime}
    \Let{\Sigma}{x^2 + y^2}
    \EndWhile

    \If{$i < i_{\max}$}
    \State \Return{$i$}
    \EndIf

    \State \Return{0}
    \EndFunction
    \end{algorithmic}
\end{algorithm}


\section{Source Code}
Following is the C++ source code example of "Hello, world!"

%\begin{lstlisting}[language = C++]
\begin{lstlisting}
    // include standard input/output stream objects:
    #include <iostream>
    // the main method:
    int main() {
    std::cout << "Hello TeX world!" << std::endl;
    }
\end{lstlisting}

\end{document}